package com.dgw.springbootactuator.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class MyHealthIndicator implements HealthIndicator {

    private final String defaultPort="80";

    @Value("${server.port}")
    private String serverPorrt;

    @Override
    public Health health() {
        int errorCode = check();
        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }
    // 定义自己检查方法
    private int check() {
        if (!defaultPort.equals(serverPorrt)){
            return 500;
        }else{ return 0;}

    }
}
